﻿#region - 版 本 注 释 -
/*----------------------------------------------------------------
 * 版权所有 (c) 2025   保留所有权利。
 * CLR版本：4.0.30319.42000
 * 机器名称：DESKTOP-GLJ2Q8J
 * 公司名称：
 * 命名空间：AutoCAD.EntityTool.Tests
 * 唯一标识：1ef392ce-4fbc-4c68-bb2f-a9416cc2aceb
 * 文件名：LineTools
 * 当前用户域：DESKTOP-GLJ2Q8J
 * 
 * 创建者：Guoweihao-79991
 * 电子邮箱：799919859@qq.com
 * 创建时间：2025/5/23 16:28:20
 * 版本：V1.0.0
 *
 * 功能描述(Description):
 * 参考文档(Reference):
 * 数据表(Tables):
 * 作者(Author):Guo
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion - 版 本 注 释 -
using AutoCAD.EntityTools;
using AutoCAD.EntityTools.Convert;
using AutoCAD.EntityTools.Jig;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//[assembly:CommandClass(typeof(AutoCAD.EntityTool.Tests.Demo))]
namespace AutoCAD.EntityTool.Tests
{
    public class Demo
    {
        /// <summary>
        /// Run
        /// </summary>
        [CommandMethod(nameof(Run))]
        public void Run()
        {
            try
            {

                Document doc = Application.DocumentManager.MdiActiveDocument;
                using (doc.LockDocument())
                {

                    var line = new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0));
                    doc.Database.AddEntityToModelSpace(line);

                    "完成了".CadAlert();
                }

            }
            catch (System.Exception ex)
            {

                System.Windows.MessageBox.Show(ex.Message);
            }
        }

        #region - 测试直线Jig -
        /// <summary>
        /// LineJigTest
        /// </summary>
        [CommandMethod(nameof(LineJig_Test))]
        public void LineJig_Test()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始直线Jig测试...");

                // 测试方法1：自动添加到模型空间
                ed.WriteMessage("\n测试方法1：自动添加到模型空间");
                List<ObjectId> lineIds = doc.CreateLines(2); // 使用颜色索引2（黄色）

                ed.WriteMessage($"\n成功创建 {lineIds.Count} 条直线");

                // 测试方法2：使用事务和指定块表记录
                ed.WriteMessage("\n\n测试方法2：使用事务和指定块表记录");

                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    List<ObjectId> lineIds2 = doc.CreateLines(trans, btr, 3, "请指定第一个点（事务模式）");

                    ed.WriteMessage($"\n成功创建 {lineIds2.Count} 条直线（事务模式）");

                    trans.Commit();
                }

                ed.WriteMessage("\n\n直线Jig测试完成！");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("LineJig_Test");
            }
        }

        /// <summary>
        /// 测试撤销功能
        /// </summary>
        [CommandMethod(nameof(LineJig_UndoTest))]
        public void LineJig_UndoTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n测试直线Jig的撤销功能...");
                ed.WriteMessage("\n请尝试使用U关键字撤销上一步操作");

                List<ObjectId> lineIds = doc.CreateLines(4); // 使用颜色索引4（青色）

                ed.WriteMessage($"\n最终创建了 {lineIds.Count} 条直线");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("LineJig_UndoTest");
            }
        }

        /// <summary>
        /// 测试闭合功能
        /// </summary>
        [CommandMethod(nameof(LineJig_CloseTest))]
        public void LineJig_CloseTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n测试直线Jig的闭合功能...");
                ed.WriteMessage("\n请创建至少3条线段后使用C关键字闭合");

                List<ObjectId> lineIds = doc.CreateLines(1); // 使用颜色索引1（红色）

                ed.WriteMessage($"\n创建了 {lineIds.Count} 条直线，{(lineIds.Count >= 3 ? "已闭合" : "未闭合")}");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("LineJig_CloseTest");
            }
        }
        #endregion

        #region - 测试圆Jig -

        /// <summary>
        /// 圆Jig测试
        /// </summary>
        [CommandMethod(nameof(CircleJig_Test))]
        public void CircleJig_Test()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始圆Jig测试...");

                // 测试单个圆创建
                ed.WriteMessage("\n测试单个圆创建：");
                ObjectId circleId = doc.CreateCircle(3); // 使用颜色索引3（绿色）

                if (!circleId.IsNull)
                {
                    ed.WriteMessage("\n单个圆创建成功！");
                }
                else
                {
                    ed.WriteMessage("\n单个圆创建取消或失败");
                }

                // 测试事务模式创建
                ed.WriteMessage("\n\n测试事务模式创建：");
                using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
                {
                    BlockTable bt = trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId circleId2 = doc.CreateCircle(trans, btr, 5, "请指定圆心点（事务模式）");

                    if (!circleId2.IsNull)
                    {
                        ed.WriteMessage("\n事务模式圆创建成功！");
                    }

                    trans.Commit();
                }

                ed.WriteMessage("\n\n圆Jig测试完成！");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("CircleJig_Test");
            }
        }

        /// <summary>
        /// 批量创建圆测试
        /// </summary>
        [CommandMethod(nameof(CircleJig_MultipleTest))]
        public void CircleJig_MultipleTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始批量创建圆测试...");

                List<ObjectId> circleIds = doc.CreateMultipleCircles(4, 5); // 创建最多5个青色圆

                ed.WriteMessage($"\n成功创建 {circleIds.Count} 个圆");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("CircleJig_MultipleTest");
            }
        }

        /// <summary>
        /// 直径方式创建圆测试
        /// </summary>
        [CommandMethod(nameof(CircleJig_DiameterTest))]
        public void CircleJig_DiameterTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始直径方式创建圆测试...");
                ed.WriteMessage("\n创建圆时请输入D关键字选择直径方式");

                ObjectId circleId = doc.CreateCircle(2); // 使用颜色索引2（黄色）

                if (!circleId.IsNull)
                {
                    ed.WriteMessage("\n直径方式创建圆成功！");
                }
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("CircleJig_DiameterTest");
            }
        }
        #endregion

        #region - 测试矩形Jig -

        /// <summary>
        /// 矩形Jig测试
        /// </summary>
        [CommandMethod(nameof(RectangleJig_Test))]
        public void RectangleJig_Test()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始矩形创建测试...");

                // 测试矩形创建
                ed.WriteMessage("\n测试矩形创建：");
                ObjectId rectangleId = doc.CreateRectangle(3); // 使用颜色索引3（绿色）

                if (!rectangleId.IsNull)
                {
                    ed.WriteMessage("\n矩形创建成功！");
                }
                else
                {
                    ed.WriteMessage("\n矩形创建取消或失败");
                }

                ed.WriteMessage("\n\n矩形创建测试完成！");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("RectangleJig_Test");
            }
        }

        /// <summary>
        /// 尺寸方式创建矩形测试
        /// </summary>
        [CommandMethod(nameof(RectangleJig_DimensionTest))]
        public void RectangleJig_DimensionTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始尺寸方式创建矩形测试...");
                ed.WriteMessage("\n创建矩形时请输入D关键字选择尺寸方式");

                ObjectId rectangleId = doc.CreateRectangle(2); // 使用颜色索引2（黄色）

                if (!rectangleId.IsNull)
                {
                    ed.WriteMessage("\n尺寸方式创建矩形成功！");
                }
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("RectangleJig_DimensionTest");
            }
        }

        /// <summary>
        /// 批量创建矩形测试
        /// </summary>
        [CommandMethod(nameof(RectangleJig_MultipleTest))]
        public void RectangleJig_MultipleTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始批量创建矩形测试...");

                List<ObjectId> rectangleIds = doc.CreateMultipleRectangles(4, 3); // 创建最多3个青色矩形

                ed.WriteMessage($"\n成功创建 {rectangleIds.Count} 个矩形");
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("RectangleJig_MultipleTest");
            }
        }

        /// <summary>
        /// 圆角矩形测试
        /// </summary>
        [CommandMethod(nameof(RectangleJig_RoundedTest))]
        public void RectangleJig_RoundedTest()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                ed.WriteMessage("\n开始圆角矩形测试...");

                // 获取圆角半径
                var radiusOptions = new PromptDistanceOptions("\n指定圆角半径:")
                {
                    DefaultValue = 5.0,
                    AllowNegative = false
                };

                var radiusResult = ed.GetDistance(radiusOptions);
                if (radiusResult.Status != PromptStatus.OK)
                    return;

                ObjectId roundedRectId = doc.CreateRoundedRectangle(radiusResult.Value, 5); // 使用颜色索引5（蓝色）

                if (!roundedRectId.IsNull)
                {
                    ed.WriteMessage("\n圆角矩形创建成功！");
                }
            }
            catch (System.Exception ex)
            {
                ex.BuildErrorMessage("RectangleJig_RoundedTest");
            }
        }
        #endregion

        #region - 测试建筑墙线 -

        /// <summary>
        /// 创建单段双线建筑墙线
        /// </summary>
        [CommandMethod(nameof(CreateContinuousDoubleWallsTest))]
        public static void CreateContinuousDoubleWallsTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            try
            {
                // 获取墙厚参数
                PromptDoubleOptions thicknessOptions = new PromptDoubleOptions("\n请输入墙厚 (默认200): ")
                {
                    DefaultValue = 200,
                    AllowZero = false,
                    AllowNegative = false
                };
                PromptDoubleResult thicknessResult = ed.GetDouble(thicknessOptions);
                if (thicknessResult.Status != PromptStatus.OK) return;

                double wallThickness = thicknessResult.Value;

                //var result = doc.CreateSingleDoubleWall(wallThickness);
                var result = doc.CreateContinuousDoubleWalls(wallThickness);
                ed.WriteMessage($"\n创建了 {result.Count} 条墙线");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\n错误: {ex.Message}");
            }
        }

        /// <summary>
        /// 从现有直线创建双线墙
        /// </summary>
        [CommandMethod(nameof(CreateDoubleWallFromLineTest))]
        public static void CreateDoubleWallFromLineTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            try
            {
                // 选择直线
                PromptEntityOptions entityOptions = new PromptEntityOptions("\n选择要转换为墙线的直线: ");
                entityOptions.SetRejectMessage("\n请选择直线对象!");
                entityOptions.AddAllowedClass(typeof(Line), false);

                PromptEntityResult entityResult = ed.GetEntity(entityOptions);
                if (entityResult.Status != PromptStatus.OK) return;

                // 获取墙厚参数
                PromptDoubleOptions thicknessOptions = new PromptDoubleOptions("\n请输入墙厚 (默认200): ")
                {
                    DefaultValue = 200,
                    AllowZero = false,
                    AllowNegative = false
                };
                PromptDoubleResult thicknessResult = ed.GetDouble(thicknessOptions);
                if (thicknessResult.Status != PromptStatus.OK) return;

                double wallThickness = thicknessResult.Value;

                var result = doc.CreateDoubleWallFromLine(entityResult.ObjectId, wallThickness);
                ed.WriteMessage($"\n从直线创建了 {result.Count} 条墙线");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\n错误: {ex.Message}");
            }
        }

        /// <summary>
        /// 测试命令 - 显示所有功能
        /// *********
        /// </summary>
        [CommandMethod("WALLTEST")]
        public static void TestAllWallCommands()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            ed.WriteMessage("\n=== 双线墙工具测试 ===");
            ed.WriteMessage("\n可用命令:");
            ed.WriteMessage("\nCreateContinuousDoubleWallsTest  - 连续绘制双线墙");
            ed.WriteMessage("\nCreateDoubleWallFromLineTest - 从直线创建双线墙");
            ed.WriteMessage("\nWALLTEST - 显示此帮助");
        }

        /// <summary>
        /// 添加墙线到数据库
        /// </summary>
        private static List<ObjectId> AddWallLinesToDatabase(List<Entity> wallLines, Database database)
        {
            var objectIds = new List<ObjectId>();

            if (wallLines == null || wallLines.Count == 0)
                return objectIds;

            using (var trans = database.TransactionManager.StartTransaction())
            {
                try
                {
                    var bt = (BlockTable)trans.GetObject(database.BlockTableId, OpenMode.ForRead);
                    var btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    foreach (var wallLine in wallLines)
                    {
                        if (wallLine != null)
                        {
                            btr.AppendEntity(wallLine);
                            trans.AddNewlyCreatedDBObject(wallLine, true);
                            objectIds.Add(wallLine.ObjectId);
                        }
                    }

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    trans.Abort();
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n数据库错误: {ex.Message}");
                }
            }

            return objectIds;
        }


        #endregion












        #region dxf 转换 dwg



        /// <summary>
        /// 测试命令 - 转换DWG为DXF
        /// </summary>
        [CommandMethod("ConvertDwgToDxfTest")]
        public void ConvertDwgToDxfTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            try
            {
                // 获取DWG文件路径
                PromptOpenFileOptions openOptions = new PromptOpenFileOptions("选择要转换的DWG文件")
                {
                    Filter = "DWG文件 (*.dwg)|*.dwg",
                    AllowUrls = false
                };

                PromptFileNameResult openResult = ed.GetFileNameForOpen(openOptions);
                if (openResult.Status != PromptStatus.OK)
                    return;

                string sourceDwgPath = openResult.StringResult;

                // 获取DXF保存路径
                PromptSaveFileOptions saveOptions = new PromptSaveFileOptions("选择DXF保存位置")
                {
                    Filter = "DXF文件 (*.dxf)|*.dxf",
                    DialogName = System.IO.Path.ChangeExtension(
                        System.IO.Path.GetFileName(sourceDwgPath), ".dxf")
                };

                PromptFileNameResult saveResult = ed.GetFileNameForSave(saveOptions);
                if (saveResult.Status != PromptStatus.OK)
                    return;

                string targetDxfPath = saveResult.StringResult;

                // 选择DXF版本
                PromptKeywordOptions versionOptions = new PromptKeywordOptions("\n选择DXF版本")
                {
                    AllowNone = true,
                    AppendKeywordsToMessage = true
                };
                versionOptions.Keywords.Add("2000", "2000", "AutoCAD 2000 (AC1015)");
                versionOptions.Keywords.Add("2004", "2004", "AutoCAD 2004 (AC1018)");
                versionOptions.Keywords.Add("2007", "2007", "AutoCAD 2007 (AC1021)");
                versionOptions.Keywords.Add("2010", "2010", "AutoCAD 2010 (AC1024)");
                versionOptions.Keywords.Add("2013", "2013", "AutoCAD 2013 (AC1027)");
                versionOptions.Keywords.Default = "2013";

                PromptResult versionResult = ed.GetKeywords(versionOptions);
                string dxfVersion = "AC1027"; // 默认版本

                if (versionResult.Status == PromptStatus.OK)
                {
                    switch (versionResult.StringResult)
                    {
                        case "2000":
                            dxfVersion = "AC1015";
                            break;
                        case "2004":
                            dxfVersion = "AC1018";
                            break;
                        case "2007":
                            dxfVersion = "AC1021";
                            break;
                        case "2010":
                            dxfVersion = "AC1024";
                            break;
                        case "2013":
                            dxfVersion = "AC1027";
                            break;
                        default:
                            dxfVersion = "AC1027";
                            break;
                    }
                }

                // 执行转换
                ed.WriteMessage("\n开始转换: " + sourceDwgPath + " -> " + targetDxfPath);

                bool result = DwgToDxfConverter.ConvertDwgToDxf(sourceDwgPath, targetDxfPath, dxfVersion);

                if (result)
                {
                    ed.WriteMessage("\n转换成功！文件已保存到: " + targetDxfPath);
                }
                else
                {
                    ed.WriteMessage("\n转换失败！正在尝试COM接口...");

                    // 尝试使用COM接口
                    bool comResult = DwgToDxfConverter.ConvertUsingComInterface(sourceDwgPath, targetDxfPath);
                    if (comResult)
                    {
                        ed.WriteMessage("\nCOM接口转换成功！");
                    }
                    else
                    {
                        ed.WriteMessage("\n所有转换方法都失败！请检查文件路径和权限。");
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\n错误: " + ex.Message);
            }
        }

        /// <summary>
        /// 批量转换测试命令
        /// </summary>
        [CommandMethod("BatchConvertDwgToDxfTest")]
        public void BatchConvertDwgToDxfTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            try
            {
                // 选择源文件夹
                PromptStringOptions sourceOptions = new PromptStringOptions("\n请输入源文件夹路径: ");
                PromptResult sourceResult = ed.GetString(sourceOptions);

                if (sourceResult.Status != PromptStatus.OK)
                    return;

                string sourceDirectory = sourceResult.StringResult;

                // 选择目标文件夹
                PromptStringOptions targetOptions = new PromptStringOptions("\n请输入目标文件夹路径: ");
                PromptResult targetResult = ed.GetString(targetOptions);

                if (targetResult.Status != PromptStatus.OK)
                    return;

                string targetDirectory = targetResult.StringResult;

                // 执行批量转换
                ed.WriteMessage("\n开始批量转换...");

                int successCount = DwgToDxfConverter.BatchConvertDwgToDxf(
                    sourceDirectory, targetDirectory, "*.dwg", "AC1027");

                ed.WriteMessage("\n批量转换完成！成功转换 " + successCount + " 个文件");
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\n错误: " + ex.Message);
            }
        }

        /// <summary>
        /// 简化测试命令
        /// </summary>
        [CommandMethod("ConvertDwgToDxfSimple")]
        public void ConvertDwgToDxfSimple()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            try
            {
                // 硬编码文件路径（测试用）
                string sourceDwgPath = @"C:\Test\drawing.dwg";
                string targetDxfPath = @"C:\Test\drawing.dxf";

                if (!System.IO.File.Exists(sourceDwgPath))
                {
                    ed.WriteMessage("\n源文件不存在: " + sourceDwgPath);
                    return;
                }

                // 执行转换
                ed.WriteMessage("\n开始转换: " + sourceDwgPath + " -> " + targetDxfPath);

                bool result = DwgToDxfConverter.ConvertDwgToDxf(sourceDwgPath, targetDxfPath);

                if (result)
                {
                    ed.WriteMessage("\n转换成功！");
                }
                else
                {
                    ed.WriteMessage("\n转换失败！");
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\n错误: " + ex.Message);
            }
        }


















































        /// <summary>
        /// 测试命令 - 转换DXF为DWG
        /// </summary>
        [CommandMethod("ConvertDxfToDwgTest")]
        public void ConvertDxfToDwgTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            try
            {
                //// 获取DXF文件路径
                //PromptOpenFileOptions openOptions = new PromptOpenFileOptions("选择要转换的DXF文件")
                //{
                //    Filter = "DXF文件 (*.dxf)|*.dxf",
                //    AllowMultiple = false
                //};

                // 获取DXF文件路径
                PromptOpenFileOptions openOptions = new PromptOpenFileOptions("选择要转换的DXF文件")
                {
                    Filter = "DXF文件 (*.dxf)|*.dxf",
                };

                PromptFileNameResult openResult = ed.GetFileNameForOpen(openOptions);
                if (openResult.Status != PromptStatus.OK)
                    return;

                string sourceDxfPath = openResult.StringResult;

                // 获取DWG保存路径
                PromptSaveFileOptions saveOptions = new PromptSaveFileOptions("选择DWG保存位置")
                {
                    Filter = "DWG文件 (*.dwg)|*.dwg",
                    DialogName = System.IO.Path.ChangeExtension(
        System.IO.Path.GetFileName(sourceDxfPath), ".dwg")
                };
                //PromptSaveFileOptions saveOptions = new PromptSaveFileOptions("选择DWG保存位置")
                //{
                //    Filter = "DWG文件 (*.dwg)|*.dwg",
                //    DefaultFileName = System.IO.Path.ChangeExtension(
                //        System.IO.Path.GetFileName(sourceDxfPath), ".dwg")
                //};

                PromptFileNameResult saveResult = ed.GetFileNameForSave(saveOptions);
                if (saveResult.Status != PromptStatus.OK)
                    return;

                string targetDwgPath = saveResult.StringResult;



                // 选择DXF版本
                PromptKeywordOptions versionOptions = new PromptKeywordOptions("\n选择DXF版本")
                {
                    AllowNone = true,
                    AppendKeywordsToMessage = true
                };
                versionOptions.Keywords.Add("2000", "2000", "AutoCAD 2000 (AC1015)");
                versionOptions.Keywords.Add("2004", "2004", "AutoCAD 2004 (AC1018)");
                versionOptions.Keywords.Add("2007", "2007", "AutoCAD 2007 (AC1021)");
                versionOptions.Keywords.Add("2010", "2010", "AutoCAD 2010 (AC1024)");
                versionOptions.Keywords.Add("2013", "2013", "AutoCAD 2013 (AC1027)");
                versionOptions.Keywords.Default = "2013";

                PromptResult versionResult = ed.GetKeywords(versionOptions);
                string dxfVersion = "AC1027"; // 默认版本

                if (versionResult.Status == PromptStatus.OK)
                {
                    switch (versionResult.StringResult)
                    {
                        case "2000":
                            dxfVersion = "AC1015";
                            break;
                        case "2004":
                            dxfVersion = "AC1018";
                            break;
                        case "2007":
                            dxfVersion = "AC1021";
                            break;
                        case "2010":
                            dxfVersion = "AC1024";
                            break;
                        case "2013":
                            dxfVersion = "AC1027";
                            break;
                        default:
                            dxfVersion = "AC1027";
                            break;
                    }
                }


                // 执行转换
                ed.WriteMessage("\n开始转换: " + sourceDxfPath + " -> " + targetDwgPath);

                bool result = DwgDxfConverter.ConvertDxfToDwg(sourceDxfPath, targetDwgPath, dxfVersion);

                if (result)
                {
                    ed.WriteMessage("\n转换成功！文件已保存到: " + targetDwgPath);
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\n错误: " + ex.Message);
            }
        }



        #endregion


    }
}
